package io.renren.modules.generator.controller;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.renren.modules.generator.entity.DeviceGasEntity;
import io.renren.modules.generator.service.DeviceGasService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 气体设备
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-25 14:30:05
 */
@RestController
@RequestMapping("generator/devicegas")
@Api("气体设备接口")
public class DeviceGasController {
    @Autowired
    private DeviceGasService deviceGasService;

    /**
     * 列表
     */
    @RequestMapping("/chartlist")
    @ApiOperation("图表数据")
    public R chartlist(@RequestParam(name = "date") String dateStr) throws ParseException {
        return R.ok().put("chartlist", deviceGasService.chartlist(dateStr));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = deviceGasService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("id") Integer id){
		DeviceGasEntity deviceGas = deviceGasService.getById(id);

        return R.ok().put("deviceGas", deviceGas);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody DeviceGasEntity deviceGas){
		deviceGasService.save(deviceGas);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody DeviceGasEntity deviceGas){
		deviceGasService.updateById(deviceGas);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Integer[] ids){
		deviceGasService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
